package com.yanqu.road.server.cmd.activity.xingyoushanshui;

import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.XingYouShanShuiProto;
import com.yanqu.road.server.cmd.CrossUnionCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.logic.MessageHelper;
import com.yanqu.road.server.manager.activity.xingyou.CrossXingYouActivity;
import com.yanqu.road.server.manager.activity.xingyou.CrossXingYouShanShuiMgr;
import com.yanqu.road.server.protocol.CrossProtocol;
import com.yanqu.road.server.protocol.Protocol;
import com.yanqu.road.utils.YanQuMessageUtils;

@Cmd(code = CrossProtocol.C_XING_YOU_SHAN_SHUI_JOINT_OPERATION, desc = "协战")
public class CrossShanShuiJointOperationCmd extends CrossUnionCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {
        XingYouShanShuiProto.ShanShuiJointOperationReq req = XingYouShanShuiProto.ShanShuiJointOperationReq.parseFrom(packet.getBytes());
        int activityId = req.getActivityId();
        CrossXingYouActivity activity = CrossXingYouShanShuiMgr.getActivity(activityId, groupId);
        if(activity != null){
            ret = activity.challengeOperation(serverId, packet.getPlayerId(), req.getIndexId());
            if(ret != 0){
                MessageHelper.sendPacket(serverId, packet.getPlayerId(), YanQuMessageUtils.buildMessage(Protocol.U_XING_YOU_SHAN_SHUI_JOINT_OPERATION,
                        XingYouShanShuiProto.ShanShuiJointOperationRsp.newBuilder().setRet(ret)));
            }
        }
    }

    @Override
    public void sendData() {

    }
}
